<?php

class Controller_Manage_Product_Create extends Controller_Manage_Abstract
{
	function execute($request)
	{
		$form = new Form_Product_Create;

		if ($request -> isPost())
		{
			// check temporary file if exists, what will be happend.
			$temp = Upload::makeTemporaryFile('photo');

			if ($form -> isValid($_POST))
			{
				$values = $form -> getValues();

				$product = Mongo_Document::factory('product');
				$product -> _id = $product -> collection() -> get_auto_increment();

				$product -> name = $values['name'];
				$product -> tags = $values['tags'];
				$product -> created_at = time();
				$product -> updated_at = time();
				$product -> price = doubleval($values['price']);
				$product -> photo = $temp;
				$product -> deals = $values['deals'];
				$product -> posted_by = Agilet::getViewer() -> _id;
				$product -> view_count = 0;
				$product -> rate_value = 0;
				$product -> comment_count = 0;
				$product -> manufactor = $values['manufactor'];
				$product -> sell_status = 'sale';
				$product -> publish_status = 'active';
				$product -> description = $values['description'];
				$product -> save(1);
			}
		}

		$request -> response = View::render($dat = array('form' => $form), 'controller/manage/edit.tpl');
	}

}
